//
//	File: OyXMLLog.h
//

#ifndef OY_XMLLOG_H
#define OY_XMLLOG_H

#include "OyGeneral.h"


// 0 - no debugging output
// 1 - basic debugging output
// 2 - comprehensive debugging output
// 3 - all output

#ifdef OY_DEBUG_OUTPUT_ALL
	#define OY_DEBUG_LEVEL 3
#endif

#ifdef OY_DEBUG_OUTPUT_NONE
	#define OY_DEBUG_LEVEL 0
#endif

#ifdef _DEBUG
	#define OY_DEBUG_LEVEL 2
#else
	#define OY_DEBUG_LEVEL 1	
#endif




class DllExport OyXMLLog
{
public:
	// The Log type parameter is used to filter out which events are
	// going to be displayed in the final Web browser output

	// There are also some combination options for ease of use:
	// 'all'		- All the below specific categories
	// 'failures'	- Only 'Error' and 'Warning'
	// 'tracking'	- 'Comment' + 'Event' + 'Debug' + 'message'
	enum EOyXMLLogType
	{
		Unknow = 0,		// Messages that didn't identify what they were
		Error,			// Fatal problems
		Warning,		// Recoverable problems with code
		Comment,		// General information and statistics
		Event,			// Caused by a specific change in state or flow of Game
		Debug,			// Intermediary/Resultant data and state related info
		Message,		// Game play or AI or network related info

		LOGTYPENUM
	};

	// The name space parameter is used to filter the messages depending on the
	// general location that the message originated from within the source code
	enum EOyXMLLogSpace
	{
		Default = 0,	// Originating in the default space
		Engine,			// The files that make up the core/underlying engine code
		Game,			// The files that make up the Client actual game logic
		UI,				// The files that make up the user interface
		Variable,		// The data storage components of the code

		NAMESPACENUM
	};

public:

	void WriteLogEntry( int iEntryType, int iNameSpace,
		const TCHAR* strSourceFile, const TCHAR* strFunction,
		int iSourceLine, const TCHAR* strMessage );

	void WriteLogHeader();
	void Destroy();

	static OyXMLLog* GetInstance() { static OyXMLLog s_xmlLog;	return &s_xmlLog; }


private:
	CRITICAL_SECTION m_csLogLockAccess;
	UINT32			 m_LogID;
	FILE			*m_fpXMLLog;

public:
	OyXMLLog(void);
	~OyXMLLog(void);
};


//////////////////////////////////////////////////////////////////////////
#define _L(x) __L(x)
#define __L(x) L##x

#if OY_DEBUG_LEVEL == 3

	#define OyLog_Write_L1( linetype, lineSpace, linetext ) \
		OyXMLLog::GetInstance()->WriteLogEntry(				\
		(linetype),							\
		(lineSpace),						\
		_L(__FILE__),						\
		_L(__FUNCTION__),					\
		__LINE__,							\
		(linetext) )

	#define OyLog_Write_L2( linetype, lineSpace, linetext ) \
		OyXMLLog::GetInstance()->WriteLogEntry(				\
		(linetype),							\
		(lineSpace),						\
		_L(__FILE__),						\
		_L(__FUNCTION__),					\
		__LINE__,							\
		(linetext) )

	#define OyLog_Write_L3( linetype, lineSpace, linetext ) \
		OyXMLLog::GetInstance()->WriteLogEntry(				\
		(linetype),							\
		(lineSpace),						\
		_L(__FILE__),						\
		_L(__FUNCTION__),					\
		__LINE__,							\
		(linetext) )

#elif OY_DEBUG_LEVEL == 2



	#define OyLog_Write_L1( linetype, lineSpace, linetext ) \
		OyXMLLog::GetInstance()->WriteLogEntry(				\
		(linetype),							\
		(lineSpace),						\
		_L(__FILE__),						\
		_L(__FUNCTION__),					\
		__LINE__,							\
		(linetext) )

	#define OyLog_Write_L2( linetype, lineSpace, linetext ) \
		OyXMLLog::GetInstance()->WriteLogEntry(				\
		(linetype),							\
		(lineSpace),						\
		_L(__FILE__),						\
		_L(__FUNCTION__),					\
		__LINE__,							\
		(linetext) )

	#define OyLog_Write_L3( linetype, lineSpace, linetext )

#elif OY_DEBUG_LEVEL == 1
	#define OyLog_Write_L1( linetype, lineSpace, linetext ) \
		OyXMLLog::GetInstance()->WriteLogEntry(				\
		(linetype),							\
		(lineSpace),						\
		_L(__FILE__),						\
		_L(__FUNCTION__),					\
		__LINE__,							\
		(linetext) )
	#define OyLog_Write_L2( linetype, lineSpace, linetext )
	#define OyLog_Write_L3( linetype, lineSpace, linetext )

#else
	#define OyLog_Write_L1( linetype, lineSpace, linetext )
	#define OyLog_Write_L2( linetype, lineSpace, linetext )
	#define OyLog_Write_L3( linetype, lineSpace, linetext )
#endif


#endif